package com.wits.qso.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.sf.json.JSONObject;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.springframework.format.annotation.DateTimeFormat;

import com.wits.platform.entity.BaseEntity;

@Entity
@Table(name="qso_course")
public class Course extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3411954306875950669L;

	/** 课程编号**/
	private String id;
	
	/** 课程名称**/
	private String title;
	
	/** 课程学时 **/
	private int period;
	
	/** 课程学校内码**/
	private String code;
	
//	/** 所属课表编码**/
//	private String btablehId;
	
	/** 课程日期起**/
	@DateTimeFormat(pattern="yyyy-MM-dd") 
	private Date dateF;
	
	/** 课程日期迄**/
	@DateTimeFormat(pattern="yyyy-MM-dd") 
	private Date dateT;
	
	private CList listId = null;
	
	@Id
	@GenericGenerator(name = "idGen", 
					strategy = "com.wits.platform.common.id.generator.IDGenerator",
					parameters={ 
								@Parameter(name = "segment_value", value = "QSO_COURSE_ID"),
								@Parameter(name="table_name",value="wits_id_generator"),
								@Parameter(name="value_column_name",value="gen_value"),
								@Parameter(name="segment_column_name",value="gen_name"),
								@Parameter(name="segment_value_length",value="10"),
								@Parameter(name="sq_format",value="%08d"),
								@Parameter(name="sq_prefix",value="CR")
					})
	@GeneratedValue(generator = "idGen")
	@Column(name = "course_id", nullable = false, insertable = true, updatable = false, length = 10)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name="course_title",length=100)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	@Column(name="course_period",length=20)
	public int getPeriod() {
		return period;
	}

	public void setPeriod(int period) {
		this.period = period;
	}	
	
	@Column(name="course_code",length=20)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

//	@Column(name="btableh_id",length=10)
//	public String getBtablehId() {
//		return btablehId;
//	}
//
//	public void setBtablehId(String btablehId) {
//		this.btablehId = btablehId;
//	}

	@Temporal(TemporalType.DATE)
	@Column(name="course_date_f")
	public Date getDateF() {
		return dateF;
	}

	public void setDateF(Date dateF) {
		this.dateF = dateF;
	}

	@Temporal(TemporalType.DATE)
	@Column(name="course_date_t")
	public Date getDateT() {
		return dateT;
	}

	public void setDateT(Date dateT) {
		this.dateT = dateT;
	}
	
	@ManyToOne
	@JoinColumn(name = "course_lst_id" )
	public CList getListId() {
		return listId;
	}

	public void setListId(CList listId) {
		this.listId = listId;
	}

	@Override
	public String display() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String toString() {
		return JSONObject.fromObject(this,Course.getBaseJsonConfig()).toString();
	}
	

}
